import * as THREE from 'three'
import { tooltipMaterial } from '../../materal'
export class Tooltip {
  constructor() {
    this.instance = new THREE.Object3D()
  }
  async draw(data, name, conf) {
    this.texture = await tooltipMaterial(data, name)
    this.texture.minFilter = THREE.LinearFilter
    if (!this.tooltip) {
      this.tooltip = new THREE.Sprite(new THREE.SpriteMaterial({
        map: this.texture,
        transparent: true,
        side: THREE.DoubleSide,
        sizeAttenuation: false
      }))
      this.tooltip.center.set(0, 1)
      // this.tooltip.position.set(0, 0, 22.5)
    }
    this.instance.add(this.tooltip)
    this.instance.position.set(10, 70, 0)
    this.instance.children[0].material.map = this.texture
    this.instance.children[0].scale.set(0.20, 0.20, 1)
    this.instance.children[0].material.map.needsUpdate = true
    // 外界传入
    if (conf) {
      const position = conf.position
      this.instance.position.set(position.x, position.y, position.z)
      const scale = conf.scale
      this.instance.children[0].scale.set(scale.x, scale.y, scale.z)
    }
  }
  setPosition(x, y, z) {
    this.instance.position.set(x, y, z)
  }
  setScale(scaleX, scalY, scaleZ) {
    this.instance.children[0].scale.set(scaleX, scalY, scaleZ)
  }
  hide() {
    this.instance.visible = false
  }
  show() {
    this.instance.visible = true
  }
}
